'use strict';
import React, {
    Component
} from 'react'
import {
    Link,
    hashHistory
} from 'react-router'

import {
    FormGroup,
    ControlLabel,
    FormControl,
    InputGroup,
    ButtonGroup,
    Button,
} from 'react-bootstrap'

import '../Scss/pjb.scss'

export default class login extends Component {
    constructor(props) {
        super(props)
    }

    login(e) {
        const data = $('.formbox').serializeArray();
        $.ajax({
            url: `/operator/login`,
            data,
            type: 'post',
            success: (res) => {
                if (res.code == 200) {
                    hashHistory.push('/home')
                    localStorage.phone = $('[name=account]').val()
                    localStorage.password = $('[name=password]').val()
                } else {
                    layer.msg(res.msg);
                }
            },
            error: () => {
                layer.alert('请检查网络连接');
            }
        })
        e.preventDefault();
        // var params = $(".formbox").serializeArray();
        // var values = {};
        // for (var item in params) {
        //     values[params[item].name] = params[item].value;
        // }
    }

    componentDidMount() {
        //记住密码
        localStorage.phone = 13320375465
        localStorage.password = 234567

        $('[name=account]').val(localStorage.phone)
        $('[name=password]').val(localStorage.password)
    }


    render() {
        return (
            <div className='pjb_loginbox'>
                <form className='formbox' onSubmit={this.login.bind(this)}>
                    <FormGroup>
                      <InputGroup>
                        <InputGroup.Addon>手机号</InputGroup.Addon>
                        <FormControl type="tel" name='account' required />
                      </InputGroup>
                      <InputGroup>
                        <InputGroup.Addon>密&nbsp;&nbsp;&nbsp;码</InputGroup.Addon>
                        <FormControl type="password" name='password' required />
                      </InputGroup>
                    </FormGroup>
                    <ButtonGroup vertical block>
                        <Button type="submit">登 录</Button>
                    </ButtonGroup>
                </form>
            </div>
        )
    }
}
